import { Controller, Get, Post, Body, Patch, Param, Delete, Query } from '@nestjs/common';
import { ClassroomService } from './classroom.service';
import { CreateClassroomDto } from './dto/create-classroom.dto';
import { UpdateClassroomDto } from './dto/update-classroom.dto';
import { Result } from '../common/dto/common.result';
import { PageClassroomDto } from './dto/page-classroom.dto';

@Controller('classroom')
export class ClassroomController {
  constructor(private readonly classroomService: ClassroomService) {
  }

  @Post('save')
  create(@Body() createClassroomDto: CreateClassroomDto) {
    this.classroomService.create(createClassroomDto);
    return Result.success();
  }

  @Get('list')
  findAll() {
    return Result.successData(this.classroomService.findAll());
  }

  @Get('/info/:id')
  async findOne(@Param('id') id: number) {
    return Result.successData(await this.classroomService.findOne(id));
  }

  @Patch('/info')
  async update(@Body() updateClassroomDto: UpdateClassroomDto) {
    await this.classroomService.update(
      updateClassroomDto.id,
      updateClassroomDto,
    );
    return Result.success();
  }

  @Delete('/info/:id')
  remove(@Param('id') id: number) {
    return Result.successData(this.classroomService.remove(id));
  }

  @Get('/list/page')
  async page(@Query() pageClassroomDto: PageClassroomDto) {
    const list = await this.classroomService.page(pageClassroomDto);
    return Result.successData(list);
  }

  /**
   * 修改状态
   * @param updateClassroomDto 
   * @returns 
   */
  @Patch('/info/status')
  async updateStatus(@Body() updateClassroomDto: UpdateClassroomDto) {
    await this.classroomService.changeStatus(updateClassroomDto.id, updateClassroomDto.status);
    return Result.success();
  }
}
